﻿// <copyright file="Article.cs" company="Microsoft Corporation">
// Copyright (c) 2008 All Right Reserved
// </copyright>
// <author>Michael S. Scherotter</author>
// <email>mischero@microsoft.com</email>
// <date>2009-03-06</date>
// <summary>NYT Article class</summary>

namespace NYTimes.Data
{
    using System;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using System.Windows.Media.Imaging;

    /// <summary>
    /// A NYT Article
    /// </summary>
    public class Article
    {
        /// <summary>
        /// the small image width
        /// </summary>
        private int smallImageWidth;

        /// <summary>
        /// Gets or sets the abstract
        /// </summary>
        public string Abstract { get; set; }

        /// <summary>
        /// Gets or sets the body
        /// </summary>
        public string Body { get; set; }

        /// <summary>
        /// Gets or sets the byline
        /// </summary>
        public string Byline { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether comments are associated 
        /// with the article (for articles from 2007 to present). 
        /// </summary>
        public bool Comments { get; set; }

        /// <summary>
        /// Gets or sets the DBpedia person names mapped to Times per_facet 
        /// terms. This field is case sensitive: values must be Mixed Case.
        /// </summary>
        public string DBpediaResource { get; set; }

        /// <summary>
        /// Gets or sets the URLs to DBpedia person names that have been mapped
        /// to Times per_facet terms. This field is case sensitive: values must be Mixed Case.
        /// </summary>
        public Uri DBpediaResourceUrl { get; set; }

        /// <summary>
        /// Gets or sets The Times desk that produced the story (e.g., Business/Financial Desk)
        /// </summary>
        public string DeskFacet { get; set; }

        /// <summary>
        /// Gets or sets the date
        /// </summary>
        public DateTime Date { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether users must pay a fee to 
        /// retrieve the full article
        /// </summary>
        public bool Fee { get; set; }

        /// <summary>
        /// Gets or sets the title
        /// </summary>
        public string Title { get; set; }

        /// <summary>
        /// Gets or sets the URL
        /// </summary>
        public Uri Url { get; set; }

        /// <summary>
        /// Gets or sets the small image height
        /// </summary>
        public int SmallImageHeight { get; set; }

        /// <summary>
        /// Gets or sets the small image width in pixels
        /// </summary>
        public int SmallImageWidth 
        { 
            get
            {
                if (this.smallImageWidth == 0)
                {
                    return this.SmallImageHeight;
                }

                return this.smallImageWidth;
            }

            set
            {
                this.smallImageWidth = value;
            }
        }

        /// <summary>
        /// Gets or sets the Small image URL
        /// </summary>
        public Uri SmallImageUrl { get; set; }
        
        /// <summary>
        /// Gets the small image
        /// </summary>
        public BitmapImage SmallImage
        {
            get
            {
                if (this.SmallImageUrl == null)
                {
                    return null;
                }

                return new BitmapImage(this.SmallImageUrl);
            }
        }

        /// <summary>
        /// Gets or sets the description facet
        /// </summary>
        public IEnumerable<string> DescriptionFacet { get; set; }

        /// <summary>
        /// Gets or sets the person facet
        /// </summary>
        public IEnumerable<string> PersonFacet { get; set; }

        /// <summary>
        /// Gets or sets the page facet
        /// </summary>
        public string PageFacet { get; set; }

        /// <summary>
        /// Gets or sets the Geographic Location facet
        /// </summary>
        public IEnumerable<string> GeoFacet { get; set; }

        /// <summary>
        /// Gets or sets The originating body  (e.g., AP, Dow Jones, The New York Times)
        /// </summary>
        public string SourceFacet { get; set; }

        /// <summary>
        /// Gets or sets the multimedia features
        /// </summary>
        public Collection<Multimedia> MultimediaFeatures { get; set; }

        /// <summary>
        /// Gets or sets the section the article appears in (on NYTimes.com)
        /// </summary>
        /// <remarks>this is the nytd_section_facet in the article data</remarks>
        public string SectionFacet { get; set; }

        /// <summary>
        /// Gets or sets a Times column title (if applicable), such as  Weddings or Ideas &amp; Trends
        /// </summary>
        /// <remarks>column_facet</remarks>
        public string ColumnFacet { get; set; }

        /// <summary>
        /// Gets the properties and values listed
        /// </summary>
        /// <returns>a string with the property names and values</returns>
        public override string ToString()
        {
            return Synergist.Utility.GetProperties(this);
        }
    }
}
